﻿//
//                       _oo0oo_
//                      o8888888o
//                      88" . "88
//                      (| -_- |)
//                      0\  =  /0
//                    ___/`---'\___
//                  .' \\|     |// '.
//                 / \\|||  :  |||// \
//                / _||||| -:- |||||- \
//               |   | \\\  -  /// |   |
//               | \_|  ''\---/''  |_/ |
//               \  .-\__  '-'  ___/-. /
//             ___'. .'  /--.--\  `. .'___
//          ."" '<  `.___\_<|>_/___.' >' "".
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//         \  \ `_.   \_ __\ /__ _/   .-` /  /
//     =====`-.____`.___ \_____/___.-`___.-'=====
//                       `=---='
//
//
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//               佛祖保佑         永无BUG
//
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#region << 版 本 注 释 >>

/*----------------------------------------------------------------
* 类 名 称 ：IActionChainExtention
* 类 描 述 ：
* 作    者 ：henrychang
* 创建时间 ：2019/1/11 15:31:45
*******************************************************************
* Copyright @ henrychang 2018. All rights reserved.
*******************************************************************
//----------------------------------------------------------------*/

#endregion << 版 本 注 释 >>

using System;
using UniRx;
using UnityEngine;
using TouchFish.NodeActionSystem;

public static partial class IActionChainExtention
{
    public static IActionChain Repeat<T>(this T selfbehaviour, int count = -1) where T : MonoBehaviour
    {
        var retNodeChain = new RepeatNodeChain(count) { Executer = selfbehaviour };
        retNodeChain.AddTo(selfbehaviour);
        return retNodeChain;
    }

    public static IActionChain Sequence<T>(this T selfbehaviour) where T : MonoBehaviour
    {
        var retNodeChain = new SequenceNodeChain { Executer = selfbehaviour };
        retNodeChain.AddTo(selfbehaviour);
        return retNodeChain;
    }

    public static IActionChain OnlyBegin(this IActionChain selfChain, Action<OnlyBeginAction> onBegin)
    {
        return selfChain.Append(OnlyBeginAction.Allocate(onBegin));
    }

    public static IActionChain Delay(this IActionChain senfChain, float seconds)
    {
        return senfChain.Append(DelayAction.Allocate(seconds));
    }

    /// <summary>
    /// Same as Delayw
    /// </summary>
    /// <param name="senfChain"></param>
    /// <param name="seconds"></param>
    /// <returns></returns>
    public static IActionChain Wait(this IActionChain senfChain, float seconds)
    {
        return senfChain.Append(DelayAction.Allocate(seconds));
    }

    public static IActionChain Event(this IActionChain selfChain, params Action[] onEvents)
    {
        return selfChain.Append(EventAction.Allocate(onEvents));
    }

    public static IActionChain Until(this IActionChain selfChain, Func<bool> condition)
    {
        return selfChain.Append(UntilAction.Allocate(condition));
    }
}